package cn.edu.pku.service;

import cn.edu.pku.entity.BookCategory;
import cn.edu.pku.entity.BookInfo;
import cn.edu.pku.mapper.BookInfoMapper;
import cn.edu.pku.vo.BookInfoResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by intelligentdroid on 2017/5/9.
 */
@Service
public class BookInfoService {

    @Autowired
    BookInfoMapper bookInfoMapper;

    public BookInfoResult addBook(BookInfo bookInfo) {
        BookInfoResult result = new BookInfoResult();
        result.setStatus(bookInfoMapper.insert(bookInfo));
        result.setData(null);
        return result;
    }

    public BookInfo selectByPrimaryKey(int id) {
        return bookInfoMapper.selectByPrimaryKey(id);
    }

    public BookInfoResult updateBook(BookInfo bookInfo) {
        BookInfoResult result = new BookInfoResult();
        result.setStatus(bookInfoMapper.updateByPrimaryKey(bookInfo));
        result.setData(null);
        return result;
    }

    public BookInfoResult deleteBook(int id) {
        BookInfoResult result = new BookInfoResult();
        result.setStatus(bookInfoMapper.deleteByPrimaryKey(id));
        result.setData(null);
        return result;
    }

    public BookInfoResult search(int id) {
        BookInfoResult result = new BookInfoResult();
        result.setData(bookInfoMapper.selectByPrimaryKey(id));
        if (result.getData()==null) {
            result.setStatus(0);
        }else {
            result.setStatus(1);
        }
        return result;
    }

    public BookInfoResult getAll() {
        BookInfoResult result = new BookInfoResult();
        result.setData(bookInfoMapper.getAll());
        if (result.getData()==null) {
            result.setStatus(0);
        }else {
            result.setStatus(1);
        }
        return result;
    }
}
